ToolLoopAgentState

data class ToolLoopAgentState(val messages: List<ModelMessage> = emptyList(), val streamingAssistantText: String = "", val currentToolCalls: List<ContentPart.ToolCall> = emptyList(), val pendingApprovals: List<PendingApproval> = emptyList(), val isStreaming: Boolean = false, val isModelLoading: Boolean = false, val error: String? = null, val totalSteps: Int = 0, val lastFinishReason: FinishReason? = null)

Engine-shape state for ToolLoopAgent.

The Vercel AI SDK's Agent interface is stateless per-call — the host passes messages, gets back GenerateResult, manages history itself. For an Android app using a long-lived @AppScope agent (no HTTP boundary, no per-request lifecycle), it's cleaner to treat the agent as a state-holder engine: the agent owns the message log, exposes ToolLoopAgent.engineState as a StateFlow, and the host drives it via ToolLoopAgent.dispatchEngineAction — the same pattern a Compose ViewModel uses for UI state.

The per-call Agent.generate / Agent.stream surface stays available (used by tests and any host that does want stateless calls). The engine surface is layered on top, not a replacement.

Constructors

Link copied to clipboard
constructor(messages: List<ModelMessage> = emptyList(), streamingAssistantText: String = "", currentToolCalls: List<ContentPart.ToolCall> = emptyList(), pendingApprovals: List<PendingApproval> = emptyList(), isStreaming: Boolean = false, isModelLoading: Boolean = false, error: String? = null, totalSteps: Int = 0, lastFinishReason: FinishReason? = null)

Properties

Link copied to clipboard

Tool calls the model has emitted in the current in-flight step.

Link copied to clipboard

Set on the most recent error, cleared at the start of the next action.

Link copied to clipboard

True during the engine's first cold load (model init, weights fault-in).

Link copied to clipboard

True while a step is actively prefilling/decoding/executing tools.

Link copied to clipboard

Finish reason of the most recent completed loop.

Link copied to clipboard

Persistent log of all messages — system, user, assistant, tool.

Link copied to clipboard

Tool calls awaiting user approval — non-empty pauses the loop.

Link copied to clipboard

Text accumulating on the in-flight assistant message, before the step closes.

Link copied to clipboard

Total step count across all actions for this agent's lifetime.